<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Source code</title>
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
</head>
<body>
<div class="sourceContainer">
<pre><span class="sourceLineNo">001</span><a name="line.1"></a>
<span class="sourceLineNo">002</span>/*<a name="line.2"></a>
<span class="sourceLineNo">003</span> * Copyright (C) 2011 Archie L. Cobbs. All rights reserved.<a name="line.3"></a>
<span class="sourceLineNo">004</span> *<a name="line.4"></a>
<span class="sourceLineNo">005</span> * $Id: ProvidesProperty.html 783 2013-11-07 17:17:09Z archie.cobbs $<a name="line.5"></a>
<span class="sourceLineNo">006</span> */<a name="line.6"></a>
<span class="sourceLineNo">007</span><a name="line.7"></a>
<span class="sourceLineNo">008</span>package org.dellroad.stuff.vaadin7;<a name="line.8"></a>
<span class="sourceLineNo">009</span><a name="line.9"></a>
<span class="sourceLineNo">010</span>import java.lang.annotation.Documented;<a name="line.10"></a>
<span class="sourceLineNo">011</span>import java.lang.annotation.ElementType;<a name="line.11"></a>
<span class="sourceLineNo">012</span>import java.lang.annotation.Retention;<a name="line.12"></a>
<span class="sourceLineNo">013</span>import java.lang.annotation.RetentionPolicy;<a name="line.13"></a>
<span class="sourceLineNo">014</span>import java.lang.annotation.Target;<a name="line.14"></a>
<span class="sourceLineNo">015</span><a name="line.15"></a>
<span class="sourceLineNo">016</span>/**<a name="line.16"></a>
<span class="sourceLineNo">017</span> * Declares that a Java method provides a read-only Vaadin {@link com.vaadin.data.Property} value in a Java class<a name="line.17"></a>
<span class="sourceLineNo">018</span> * whose instances back the items in a {@link com.vaadin.data.Container}.<a name="line.18"></a>
<span class="sourceLineNo">019</span> *<a name="line.19"></a>
<span class="sourceLineNo">020</span> * &lt;p&gt;<a name="line.20"></a>
<span class="sourceLineNo">021</span> * {@link ProvidesProperty &amp;#64;ProvidesProperty} and {@link ProvidesPropertySort &amp;#64;ProvidesPropertySort} method annotations<a name="line.21"></a>
<span class="sourceLineNo">022</span> * can be used to automatically generate a list of {@link PropertyDef}s and a {@link PropertyExtractor} using a<a name="line.22"></a>
<span class="sourceLineNo">023</span> * {@link ProvidesPropertyScanner}. This happens automatically when using the appropriate constructors of the various<a name="line.23"></a>
<span class="sourceLineNo">024</span> * {@link com.vaadin.data.Container} classes in this package.<a name="line.24"></a>
<span class="sourceLineNo">025</span> * &lt;/p&gt;<a name="line.25"></a>
<span class="sourceLineNo">026</span> *<a name="line.26"></a>
<span class="sourceLineNo">027</span> * &lt;p&gt;<a name="line.27"></a>
<span class="sourceLineNo">028</span> * This annotation indicates that a read-only Vaadin {@link com.vaadin.data.Property} having the {@linkplain #value specified name}<a name="line.28"></a>
<span class="sourceLineNo">029</span> * and type derived from the method's return value is accessible by reading that method.<a name="line.29"></a>
<span class="sourceLineNo">030</span> * Annotated methods must have zero parameters.<a name="line.30"></a>
<span class="sourceLineNo">031</span> * &lt;/p&gt;<a name="line.31"></a>
<span class="sourceLineNo">032</span> *<a name="line.32"></a>
<span class="sourceLineNo">033</span> * &lt;p&gt;<a name="line.33"></a>
<span class="sourceLineNo">034</span> * For example:<a name="line.34"></a>
<span class="sourceLineNo">035</span> * &lt;blockquote&gt;&lt;pre&gt;<a name="line.35"></a>
<span class="sourceLineNo">036</span> * // Container backing object class<a name="line.36"></a>
<span class="sourceLineNo">037</span> * public class User {<a name="line.37"></a>
<span class="sourceLineNo">038</span> *<a name="line.38"></a>
<span class="sourceLineNo">039</span> *     public static final String USERNAME_PROPERTY = "username";<a name="line.39"></a>
<span class="sourceLineNo">040</span> *     public static final String REAL_NAME_PROPERTY = "realName";<a name="line.40"></a>
<span class="sourceLineNo">041</span> *<a name="line.41"></a>
<span class="sourceLineNo">042</span> *     private String username;<a name="line.42"></a>
<span class="sourceLineNo">043</span> *     private String realName;<a name="line.43"></a>
<span class="sourceLineNo">044</span> *<a name="line.44"></a>
<span class="sourceLineNo">045</span> *     public String getUsername() {<a name="line.45"></a>
<span class="sourceLineNo">046</span> *         return this.username;<a name="line.46"></a>
<span class="sourceLineNo">047</span> *     }<a name="line.47"></a>
<span class="sourceLineNo">048</span> *     public void setUsername(String username) {<a name="line.48"></a>
<span class="sourceLineNo">049</span> *         this.username = username;<a name="line.49"></a>
<span class="sourceLineNo">050</span> *     }<a name="line.50"></a>
<span class="sourceLineNo">051</span> *<a name="line.51"></a>
<span class="sourceLineNo">052</span> *     &lt;b&gt;&amp;#64;ProvidesProperty&lt;/b&gt;                     // property name "realName" is implied by method name<a name="line.52"></a>
<span class="sourceLineNo">053</span> *     public String getRealName() {<a name="line.53"></a>
<span class="sourceLineNo">054</span> *         return this.realName;<a name="line.54"></a>
<span class="sourceLineNo">055</span> *     }<a name="line.55"></a>
<span class="sourceLineNo">056</span> *     public void setRealName(String realName) {<a name="line.56"></a>
<span class="sourceLineNo">057</span> *         this.realName = realName;<a name="line.57"></a>
<span class="sourceLineNo">058</span> *     }<a name="line.58"></a>
<span class="sourceLineNo">059</span> *<a name="line.59"></a>
<span class="sourceLineNo">060</span> *     &lt;b&gt;&amp;#64;ProvidesProperty(USERNAME_PROPERTY)&lt;/b&gt;  // display usernames in fixed-width font<a name="line.60"></a>
<span class="sourceLineNo">061</span> *     private Label usernameProperty() {<a name="line.61"></a>
<span class="sourceLineNo">062</span> *         return new Label("&amp;lt;code&amp;gt;" + StringUtil.escapeHtml(this.username) + "&amp;lt;/code&amp;gt;", ContentMode.HTML);<a name="line.62"></a>
<span class="sourceLineNo">063</span> *     }<a name="line.63"></a>
<span class="sourceLineNo">064</span> * }<a name="line.64"></a>
<span class="sourceLineNo">065</span> *<a name="line.65"></a>
<span class="sourceLineNo">066</span> * // User container class<a name="line.66"></a>
<span class="sourceLineNo">067</span> * public class UserContainer extends SimpleKeyedContainer&amp;lt;String, User&amp;gt; {<a name="line.67"></a>
<span class="sourceLineNo">068</span> *<a name="line.68"></a>
<span class="sourceLineNo">069</span> *     public UserContainer() {<a name="line.69"></a>
<span class="sourceLineNo">070</span> *         super(&lt;b&gt;User.class&lt;/b&gt;);<a name="line.70"></a>
<span class="sourceLineNo">071</span> *     }<a name="line.71"></a>
<span class="sourceLineNo">072</span> *<a name="line.72"></a>
<span class="sourceLineNo">073</span> *     &amp;#64;Override<a name="line.73"></a>
<span class="sourceLineNo">074</span> *     public String getKeyFor(User user) {<a name="line.74"></a>
<span class="sourceLineNo">075</span> *         return user.getUsername();<a name="line.75"></a>
<span class="sourceLineNo">076</span> *     }<a name="line.76"></a>
<span class="sourceLineNo">077</span> * }<a name="line.77"></a>
<span class="sourceLineNo">078</span> *<a name="line.78"></a>
<span class="sourceLineNo">079</span> * // Create container holding all users<a name="line.79"></a>
<span class="sourceLineNo">080</span> * UserContainer container = new UserContainer();<a name="line.80"></a>
<span class="sourceLineNo">081</span> * container.load(this.userDAO.getAllUsers());<a name="line.81"></a>
<span class="sourceLineNo">082</span> *<a name="line.82"></a>
<span class="sourceLineNo">083</span> * // Build table showing users<a name="line.83"></a>
<span class="sourceLineNo">084</span> * Table table = new Table();<a name="line.84"></a>
<span class="sourceLineNo">085</span> * table.setColumnHeader(User.USERNAME_PROPERTY, "User");<a name="line.85"></a>
<span class="sourceLineNo">086</span> * table.setColumnHeader(User.REAL_NAME_PROPERTY, "Name");<a name="line.86"></a>
<span class="sourceLineNo">087</span> * table.setVisibleColumns(User.USERNAME_PROPERTY, User.REAL_NAME_PROPERTY);<a name="line.87"></a>
<span class="sourceLineNo">088</span> *<a name="line.88"></a>
<span class="sourceLineNo">089</span> * // Select user "jsmith" in the table<a name="line.89"></a>
<span class="sourceLineNo">090</span> * table.setValue("jsmith");<a name="line.90"></a>
<span class="sourceLineNo">091</span> * ...<a name="line.91"></a>
<span class="sourceLineNo">092</span> * &lt;/pre&gt;&lt;/blockquote&gt;<a name="line.92"></a>
<span class="sourceLineNo">093</span> * &lt;/p&gt;<a name="line.93"></a>
<span class="sourceLineNo">094</span> *<a name="line.94"></a>
<span class="sourceLineNo">095</span> * &lt;p&gt;<a name="line.95"></a>
<span class="sourceLineNo">096</span> * Some details regarding {@link ProvidesProperty &amp;#64;ProvidesProperty} annotations on methods:<a name="line.96"></a>
<span class="sourceLineNo">097</span> *  &lt;ul&gt;<a name="line.97"></a>
<span class="sourceLineNo">098</span> *  &lt;li&gt;Only non-void methods taking zero parameters are supported; {@link ProvidesProperty &amp;#64;ProvidesProperty}<a name="line.98"></a>
<span class="sourceLineNo">099</span> *      annotations on other methods are ignored&lt;/li&gt;<a name="line.99"></a>
<span class="sourceLineNo">100</span> *  &lt;li&gt;Protected, package private, and private methods are supported.&lt;/li&gt;<a name="line.100"></a>
<span class="sourceLineNo">101</span> *  &lt;li&gt;{@link ProvidesProperty &amp;#64;ProvidesProperty} annotations on interface methods are supported&lt;/li&gt;<a name="line.101"></a>
<span class="sourceLineNo">102</span> *  &lt;li&gt;If a method and the superclass or superinterface method it overrides are both annotated with<a name="line.102"></a>
<span class="sourceLineNo">103</span> *      {@link ProvidesProperty &amp;#64;ProvidesProperty}, then the overridding method's annotation takes precedence.<a name="line.103"></a>
<span class="sourceLineNo">104</span> *  &lt;li&gt;If two methods with different names are annotated with {@link ProvidesProperty &amp;#64;ProvidesProperty} for the same<a name="line.104"></a>
<span class="sourceLineNo">105</span> *      {@linkplain #value property name}, then the declaration in the class which is a sub-type of the other<a name="line.105"></a>
<span class="sourceLineNo">106</span> *      wins (if the two methods are delcared in the same class, an exception is thrown). This allows subclasses<a name="line.106"></a>
<span class="sourceLineNo">107</span> *      to "override" which method supplies a given property.&lt;/li&gt;<a name="line.107"></a>
<span class="sourceLineNo">108</span> *  &lt;/ul&gt;<a name="line.108"></a>
<span class="sourceLineNo">109</span> * &lt;/p&gt;<a name="line.109"></a>
<span class="sourceLineNo">110</span> *<a name="line.110"></a>
<span class="sourceLineNo">111</span> * &lt;p&gt;<a name="line.111"></a>
<span class="sourceLineNo">112</span> * To control how properties are sorted (e.g., in tables), see {@link ProvidesPropertySort &amp;#64;ProvidesPropertySort}.<a name="line.112"></a>
<span class="sourceLineNo">113</span> * &lt;/p&gt;<a name="line.113"></a>
<span class="sourceLineNo">114</span> *<a name="line.114"></a>
<span class="sourceLineNo">115</span> * @see ProvidesPropertySort<a name="line.115"></a>
<span class="sourceLineNo">116</span> * @see ProvidesPropertyScanner<a name="line.116"></a>
<span class="sourceLineNo">117</span> */<a name="line.117"></a>
<span class="sourceLineNo">118</span>@Retention(RetentionPolicy.RUNTIME)<a name="line.118"></a>
<span class="sourceLineNo">119</span>@Target({ ElementType.METHOD, ElementType.FIELD })<a name="line.119"></a>
<span class="sourceLineNo">120</span>@Documented<a name="line.120"></a>
<span class="sourceLineNo">121</span>public @interface ProvidesProperty {<a name="line.121"></a>
<span class="sourceLineNo">122</span><a name="line.122"></a>
<span class="sourceLineNo">123</span>    /**<a name="line.123"></a>
<span class="sourceLineNo">124</span>     * Get the name of the Vaadin property. If this is left unset (empty string), then the<a name="line.124"></a>
<span class="sourceLineNo">125</span>     * bean property name of the annotated bean property "getter" method is used.<a name="line.125"></a>
<span class="sourceLineNo">126</span>     */<a name="line.126"></a>
<span class="sourceLineNo">127</span>    String value() default "";<a name="line.127"></a>
<span class="sourceLineNo">128</span>}<a name="line.128"></a>
<span class="sourceLineNo">129</span><a name="line.129"></a>




























































</pre>
</div>
</body>
</html>
